/*
 * ContextPropertySpace.java
 *
 * Created on 20 de diciembre de 2004, 14:08
 */

package ocp.context;

/**
 *
 * @author  nacho
 */
public class ContextPropertySpace implements java.io.Serializable  {

    public static final int INFINITY_CARDINALITY = -2;
    public static final int UNKNOWN_CARDINALITY = -1;
    public static final int NOT_DEFINED = 0;
    public static final int ALL_VALUES_FROM  = 1;
    public static final int SOME_VALUES_FROM = 2;
    private static final int NUMBER = 3;
    public static final String [] names = {"NOT DEFINED", "ALL_VALUES_FROM", "SOME_VALUES_FROM"};
    protected int minCardinality = UNKNOWN_CARDINALITY;
    protected int maxCardinality = UNKNOWN_CARDINALITY;
    protected int type = NOT_DEFINED;
    protected String contextClass;
        
    
    /**
     * Creates a new instance of ContextPropertySpace
     */
    public ContextPropertySpace(String cc, int minCardinality, int maxCardinality, int type) {
        this.contextClass = cc;
        this.minCardinality = minCardinality; 
        this.maxCardinality = maxCardinality; 
        if ((type < NUMBER) || (type >= 0)) this.type = type;
    }

    public int getMaxCardinality() { return maxCardinality; }
    public int getMinCardinality() { return minCardinality; }
    public void setMaxCardinality(int maxCardinality)   { this.maxCardinality = maxCardinality; }
    public void setMinCardinality(int minCardinality)   { this.minCardinality = minCardinality; }
    public int getRestrictionType(){ return type; }
    public String getContextClass()   { return contextClass; }
    
    public String toXML()   { 
        String xml = "<SpaceContext>\n";
        xml += "\t<ContextClass>"+contextClass+"</ContextClass>\n";
        xml += "\t<MaxCardinality>"+(maxCardinality==UNKNOWN_CARDINALITY?"not defined":(maxCardinality==INFINITY_CARDINALITY?"infinity":""+maxCardinality))+"</MaxCardinality>\n";
        xml += "\t<MinCardinality>"+(minCardinality==UNKNOWN_CARDINALITY?"not defined":""+minCardinality)+"</MinCardinality>\n";
        xml += "\t<Restriction>"+names[type]+"</Restriction>\n";
        xml += "</SpaceContext>";
        
        return xml;
    }
    
}
